var common = require("../../utils/util.js");
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabActive: 1,  //1待接单 2进行中 3已完成
    tabList: ['待接单', '进行中', '已完成'],
    type: 'self',  //self自己  accept接单
    // 列表分页参数
    currentNo: 1,
    isajax: false,
    listarr: [],
    isnodata: false,
    pagesize: 10,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let type = options.ordertype && options.ordertype || 'self'
    this.setData({
      tabActive: options.tab && options.tab || 1,
      type,
    })
    wx.setNavigationBarTitle({
      title: type=='self'? '我发布的订单': '我的跑腿订单'
    })
  },
  onShow() {
    this.change_data_list();
  },
  goDetail(e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/order/detail?id=${id}`,
    })
  },

  switchTab(e) {
    this.setData({
      tabActive: e.target.dataset.index + 1,
      currentNo: 1,
      isajax: false,
      listarr: [],
      isnodata: false,
    })
    this.change_data_list();
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.get_data_list();
  },

  /**初次请求，列表数据**/
  change_data_list: function () {
    let url = this.data.type=='accept'? common.config.RunnerOrderList : common.config.OrderList;
    common.changelistdata_user(this, url, {
      type: this.data.type,
      order_status: this.data.tabActive,
      order_type: this.data.tabActive
    });
  },

  /**下拉加载更多，列表数据**/
  get_data_list: function () {
    let url = this.data.type=='accept'? common.config.RunnerOrderList : common.config.OrderList;
    common.getlistdata_user(this, url, {
      type: this.data.type,
      order_status: this.data.tabActive,
      order_type: this.data.tabActive
    });
  },
})
